package com.smart.common.utils.redis.redistask;

import com.smart.common.utils.redis.RedisManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 订单信息推送任务类
 * @author zhouwc
 *
 */
public class RedisLpushTask implements Runnable{
	
	private final static Logger redisLogger = LoggerFactory.getLogger("redisLogger");
	
	private RedisManager redisManager;
	private String key;
	private String value;
	private int index;
	
	public RedisLpushTask (RedisManager redisManager,String key,String value,int index) {
		this.redisManager = redisManager;
		this.key = key;
		this.value = value;
		this.index = index;
	}

	@Override
	public void run() {
		try {
			//FIXME 19-06-19 20:40:19 -error:加油站派券记录:key=stationEcp:2019-06-17:5,value=8071694,setRedisLpush=134,getValue=8075854
			//日志记录里所有获取的值都是8075854
			Long setRedisLpush = redisManager.setRedisLpush(key, value, index);
			if(setRedisLpush == null) {
				//记录失败日志
				redisLogger.error("error:加油站派券记录:key="+key+",value="+value+",setRedisLpush="+setRedisLpush);
			}else {
				//FIXME 检查失败待处理
//				List<String> redisList = redisManager.getRedisList(key, 1);
//				
//				String v = redisList.get(setRedisLpush.intValue()-1);
//				if(!value.equals(v)) {
//					redisLogger.error("error:加油站派券记录:key="+key+",value="+value+",setRedisLpush="+setRedisLpush+",getValue="+v);
//				}
			}
			
		} catch (Exception e) {
			
			redisLogger.error("error:加油站派券记录:key="+key+",value="+value+",msg="+e.getMessage());
			redisLogger.error("error",e);
			
			e.printStackTrace();
		}
	}
}
